import React, { Component } from 'react'


//引入标头
import Header from '../../components/Header/Header'

//引入请求优惠券
import { reqgetcoupon } from '../../http/api'

import { Card, Toast, Button } from 'antd-mobile'

import './You.less'

export default class You extends Component {

    constructor() {
        super()
        this.state = {
            you: []
        }
    }

    componentDidMount() {
        //1.一进来就发送购物车请求
        this.reqyou()
    }
    //2.使用await async来发送请求 
    async reqyou() {
        let res = await reqgetcoupon()
        if (res.data.code == 200) {
            this.setState({
                you: res.data.list
            })

        }
    }

    render() {
        let { you } = this.state
        return (
            <div className='youhui app'>
                <Header title='优惠券' back='back'></Header>
                {you.map((item, index) => {
                    return (
                        <div key={index}>
                            {item.content ? (<div>
                                {item.content.map(i => {
                                    return <Card className='card'
                                        title={'￥'+i.money}
                                        extra={i.title}
                                        key={i.id}
                                    >
                                           {i.description}
                                           </Card>
                                })}
                            </div>) : (null)}
                        </div>
                    )
                })}
                <footer>抢更多好券</footer>
            </div>
        )
    }
}
